<?php

namespace app\test630\controller;

use app\test630\model\Role;
use think\Controller;

use app\test630\model\Cuo as CuoModel;
use think\Request;

class Cuo extends Controller
{
    public function index()
    {
        //根据 用户的角色id 拿到相应的权限
        $r_id = session('r_id');
        $username = session('userInfo');
      $res =   Role::where('id',$r_id)->find();


            $data = CuoModel::all();


        return view('cuo/index',compact('res','data','username'));
    }

    /**
     *
     * 申请添加
     *Method create
     *user:大飞
     *time:2021/6/30 9:24
     */
    public function create()
    {
        $r_id = session('r_id');
        $username = session('userInfo');
        $res =   Role::where('id',$r_id)->find();

        return view('cuo/create',compact('r_id','username','res'));
    }


    /**
     * 处理添加信息
     *Method save
     *user:大飞
     *time:2021/6/30 9:34
     */
    public function save(Request $request)
    {
        $data = $request->param();
        $data['r_id'] = session('r_id');
        $file = $request->file('images');

        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move( 'uploads');
        if($info){

            $img =  $info->getSaveName();
        }

        $data['images']= 'www.self.com/uploads/'.$img;

       $res =  CuoModel::create($data,true);
        if ($res)
        {
            return $this->success('添加成功!','login/index');
        }else{
            return $this->success('添加失败!');

        }
    }
}
